<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Quick parse input string</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="messageformatter.getpattern.html">« MessageFormatter::getPattern</a></li>
      <li style="float: right;"><a href="messageformatter.parse.html">MessageFormatter::parse »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.messageformatter.html">MessageFormatter</a></li>
    <li>Quick parse input string</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="messageformatter.parsemessage" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">MessageFormatter::parseMessage</h1>
  <h1 class="refname">msgfmt_parse_message</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8, PECL intl &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">MessageFormatter::parseMessage</span> -- <span class="refname">msgfmt_parse_message</span> &mdash; <span class="dc-title">Quick parse input string</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-messageformatter.parsemessage-description">
  <h3 class="title">说明</h3>
  <p class="para">
   面向对象风格
  </p>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><strong>MessageFormatter::parseMessage</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$locale</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$pattern</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$message</code></span>): <span class="type"><span class="type">array</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   过程化风格
  </p>
  <div class="methodsynopsis dc-description"><span class="methodname"><strong>msgfmt_parse_message</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$locale</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$pattern</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$message</code></span>): <span class="type"><span class="type">array</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   Parses input string without explicitly creating the formatter object. Use
   this function when the format operation is done only once and does not need
   any parameters or state to be kept.
  </p>
 </div>

 
 <div class="refsect1 parameters" id="refsect1-messageformatter.parsemessage-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">locale</code></dt>

     <dd>

      <p class="para">
       The locale to use for parsing locale-dependent parts
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">pattern</code></dt>

     <dd>

      <p class="para">
       The pattern with which to parse the <code class="parameter">message</code>.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">message</code></dt>

     <dd>

      <p class="para">
       The <span class="type">string</span> to parse, conforming to the <code class="parameter">pattern</code>.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 
 
 <div class="refsect1 returnvalues" id="refsect1-messageformatter.parsemessage-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   An <span class="type">array</span> containing items extracted, or <strong><code>false</code></strong> on error
  </p>
 </div>

 
 <div class="refsect1 examples" id="refsect1-messageformatter.parsemessage-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-2380">
   <p><strong>示例 #1 <span class="function"><strong>msgfmt_parse_message()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$fmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">msgfmt_parse_message</span><span style="color: #007700">(</span><span style="color: #DD0000">'en_US'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"{0,number,integer}&nbsp;monkeys&nbsp;on&nbsp;{1,number,integer}&nbsp;trees&nbsp;make&nbsp;{2,number}&nbsp;monkeys&nbsp;per&nbsp;tree"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"4,560&nbsp;monkeys&nbsp;on&nbsp;123&nbsp;trees&nbsp;make&nbsp;37.073&nbsp;monkeys&nbsp;per&nbsp;tree"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_export</span><span style="color: #007700">(</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$fmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">msgfmt_parse_message</span><span style="color: #007700">(</span><span style="color: #DD0000">'de'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"{0,number,integer}&nbsp;Affen&nbsp;auf&nbsp;{1,number,integer}&nbsp;Bäumen&nbsp;sind&nbsp;{2,number}&nbsp;Affen&nbsp;pro&nbsp;Baum"</span><span style="color: #007700">,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"4.560&nbsp;Affen&nbsp;auf&nbsp;123&nbsp;Bäumen&nbsp;sind&nbsp;37,073&nbsp;Affen&nbsp;pro&nbsp;Baum"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_export</span><span style="color: #007700">(</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
  <div class="example" id="example-2381">
   <p><strong>示例 #2 OO example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$fmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">MessageFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">parseMessage</span><span style="color: #007700">(</span><span style="color: #DD0000">'en_US'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"{0,number,integer}&nbsp;monkeys&nbsp;on&nbsp;{1,number,integer}&nbsp;trees&nbsp;make&nbsp;{2,number}&nbsp;monkeys&nbsp;per&nbsp;tree"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"4,560&nbsp;monkeys&nbsp;on&nbsp;123&nbsp;trees&nbsp;make&nbsp;37.073&nbsp;monkeys&nbsp;per&nbsp;tree"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_export</span><span style="color: #007700">(</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$fmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">MessageFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">parseMessage</span><span style="color: #007700">(</span><span style="color: #DD0000">'de'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"{0,number,integer}&nbsp;Affen&nbsp;auf&nbsp;{1,number,integer}&nbsp;Bäumen&nbsp;sind&nbsp;{2,number}&nbsp;Affen&nbsp;pro&nbsp;Baum"</span><span style="color: #007700">,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"4.560&nbsp;Affen&nbsp;auf&nbsp;123&nbsp;Bäumen&nbsp;sind&nbsp;37,073&nbsp;Affen&nbsp;pro&nbsp;Baum"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_export</span><span style="color: #007700">(</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
  <p class="para">以上例程会输出：</p>
  <div class="example-contents screen">
<div class="cdata"><pre>
array (
  0 =&gt; 4560,
  1 =&gt; 123,
  2 =&gt; 37.073,
)
array (
  0 =&gt; 4560,
  1 =&gt; 123,
  2 =&gt; 37.073,
)
</pre></div>
  </div>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-messageformatter.parsemessage-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="messageformatter.create.html" class="function" rel="rdfs-seeAlso">msgfmt_create()</a> - Constructs a new Message Formatter</span></li>
    <li class="member"><span class="function"><a href="messageformatter.formatmessage.html" class="function" rel="rdfs-seeAlso">msgfmt_format_message()</a> - Quick format message</span></li>
    <li class="member"><span class="function"><a href="messageformatter.parse.html" class="function" rel="rdfs-seeAlso">msgfmt_parse()</a> - Parse input string according to pattern</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>